home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9008 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: crl.crl.com!not-for-mail
  2. From: bobfry@crl.com (Robert Fry)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: do || die;
  5. Date: 7 Mar 1996 09:59:46 -0800
  6. Organization: CRL Dialup Internet Access
  7. Message-ID: <4hn86i$rpm@crl.crl.com>
  8. References: <1996Mar7.052636.59812@ucl.ac.uk>
  9. NNTP-Posting-Host: crl.com
  10.  
  11. slidel@bsm.bioc.ucl.ac.uk (Timothy Slidel) writes:
  12.  
  13. >Whilst it seems to work ok - is it considered bad style to use
  14. >logical operator expressions as conditional statements on their own, a la
  15. >Perl?
  16.  
  17. >e.g. if I want to decrement i only when it is != 0:
  18.  
  19. >i && i--;
  20.  
  21. I would consider it very poor style, especially when the more common 
  22. alternative:
  23.  
  24. if (i) i--;
  25.  
  26. takes all of two more characters to type, is more clear to a stranger 
  27. coming upon the code (or yourself, maintaining it), and runs exactly as 
  28. fast and should compile to the same size, as well.
  29.  
  30. In general, I avoid the use of idiosyncratic constructs like the one you 
  31. suggest, except when there is some definite advantage to them. 
  32. Gratuitous use of anything like the above is something I find to be 
  33. a prime cause of maintenance headaches, and so a poor idea. If I find I 
  34. have a real need for something (such as the old XOR-based trick for 
  35. swapping values), I document it heavily and note any limitations 
  36. prominently. Assuming I can spot them -- such things often have 
  37. non-obvious drawbacks that can cause troubles.
  38.  
  39.   Bob
  40.